# -*- coding: utf-8 -*-
# @Time    : 2021/3/31 19:00
# @Author  : 夏思毅
# @Email   : 2739124228@qq.com
# @File    : 三乐购物系统.py
# @Software: PyCharm

# import pygame
# # 音乐的路径
# file=r'F:\CloudMusic\折戸伸治 - 日々の遑.mp3'
# # 初始化
# pygame.mixer.init()
# # 加载音乐文件
# track = pygame.mixer.music.load(file)
# # 开始播放音乐流
# pygame.mixer.music.play()



print(('\033[1;35m"欢迎来到暮仙州琅琊阁" \033[0m').center(80,"="))
#登录界面
# 登录及注册提示
# 可登录用户
swordsmanlist = {'风清扬': '123456', '李牧之': '123456', '1': '1', '吴少侠': '我是大傻逼'}
# 商品信息
goodslist = {'g1':{'名字':'黑虎经','价格':'1560','stock':'2'},
             'g2':{'名字':'石磐法','价格':'1877','stock':'3'},
             'g3':{'名字':'清风剑','价格':'2560','stock':'6'},
             'g4':{'名字':'悍山拳','价格':'1045','stock':'5'}}
# 已购信息
buylist = {}
count = 0
#随时exit
def ex(input):
    if input == 'exit':
        for i, j in buylist.items():
            print("编号:", i)
            print("商品名称：", j['名字'])
            print("商品价格：", j['价格'])
            print("已购数量：", j['count'])
            # del buylist['stock']
            # print(buylist)
        print('腰包里还有',money)
        exit()
    else:
        pass
# 实现注册功能
def login():
    namelogin = input("烦请留下信物：")
    passwordlogin = input("亦请留下信诀：")
    swordsmanlist.update({f'{namelogin}': f'{passwordlogin}'})
    print(('\033[1;35m申请成功 \033[0m').center(80, '*'))
# 登录功能
def int():
    print(('\033[1;35m温馨提示：江湖险恶，为了少侠您的安全，还请出示信物及信诀。 \033[0m').center(69, "*"))
    while 1:
        name = input("信物：")
        if name in swordsmanlist.keys():
            password = input("信诀：")
            if password == swordsmanlist[name]:
                print((f'\033[1;36m欢迎{name}入阁 \033[0m').center(80, '+'))
                break
            else:
                print("再想想,非此信诀")
        else:
            print("请三思,非此信物")

# 定义全球变量
def qian():
    global money
    money = float(input("可否告知本次所携带灵石数量："))
    ex(input("输入洋文exit可退出："))
    if money < 1041:
        print("少侠盘缠不够，还请回")
        exit()
# 查看商品列表
def check():
    global money
    money -= 10
    for i, j in goodslist.items():
        print(f"编号：{i}", f"名字：{j['名字']}", f"价格：{j['价格']}", f"库存：{j['stock']}")
    ex(input("输入洋文exit可退出："))
# 购买功能
def buy():
    global money
    money -= 1
    choice = input("欢迎选购,请输入购买商品编号:")
    number = input("要多少呢？")
    while choice in goodslist.keys():
        gc = goodslist[choice]
        if number < gc['stock']:
            money -= float(f"{goodslist[choice]['价格']}") * float(number)
            if choice in buylist:
                bc = buylist[choice]
                bc['count'] = float(bc['count']) + float(number)
                # 购买数量
                gc['stock'] = float(gc['stock']) - 1
                # 库存
            else:
                gc['count'] = number
                # 库存
                gc['stock'] = float(gc['stock']) - float(number)
                # 库存
                buylist[choice] = gc
            print(f"您已成功购买{goodslist[choice]['名字']}")
            ex(input("输入洋文exit可退出："))
            # print(goodslist[choice])
            break
        else:
            print("买多了，你没那么多钱，改改")
            break
    else:
        print("没有该种商品，请重新选择。")
# 查看已购买
def checkbuy():
    global money
    money -= 2
    if buylist:
        print(('\033[1;36m已购信息 \033[0m').center(100, "*"))
        for i, j in buylist.items():
            print("编号:", i, end=' ')
            print("商品名称：", j['名字'], end=' ')
            print("商品价格：", j['价格'], end=' ')
            print("已购数量：", j['count'])
        print(('\033[1;36m欢迎下次光临~ \033[0m').center(97, "*"))
        ex(input("输入洋文exit可退出："))
    else:
        print(('\033[1;36m已购信息 \033[0m').center(100, "*"))
        print("暂未购买任何商品")
        print("剩余灵石：", money)
        print(('\033[1;36m欢迎下次光临~ \033[0m').center(97, "*"))


#主程序
while 1:
    yw = input("登入 申请（别的不行嗷）：")
    if yw=='申请':
        login()
    if yw=='登入':
        int()
        qian()
        while 1:
            print("少侠若想购买商品，还请消费1颗灵石".center(73, '-'))
            print("少侠若想查看已购买商品，还请消费2颗灵石".center(71, '-'))
            print("少侠若想查看商品信息，还请消费10颗灵石".center(72,'-'))
            give = input("请投放灵石：")
            ex(input("输入洋文exit可退出："))
            if give == '10':
                check()
                # 查看商品信息
            elif give == '1':
                buy()
            elif give == '2':
                checkbuy()
            else:
                    print("不识数吗")
                    continue




